<template>
    <div style="width:100%;height:100%;overflow: hidden;">
     <div id="main-map"></div>
    </div>
</template>
<script>
import imag from '../../src/assets/timg.gif'
export default {
    data () {
        return {
         map:null,
         context:null,
         data :null,
         image:null
        }
    },
    mounted() {
        this.init();
        console.log(777)
    },
    methods:{
        init(){
          this.smartmapx.mapbase = 'http://www.smartmapx.com';
          this.smartmapx.apikey = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYmYiOjE1MzcxODM1OTgsImRhdGEiOiJ7XCJsb2dpbl9uYW1lXCI6XCJyb290XCIsXCJnZW5kZXJcIjoyLFwidXNlcl9pZFwiOlwiZm1fc3lzdGVtX3VzZXJfcm9vdFwiLFwidXNlcl9uYW1lXCI6XCJyb290XCIsXCJ1c2VyX29yaWdpbl9pZFwiOlwiZm1fbG9jYWxcIixcInByb2R1Y3RfaWRcIjpcIlwiLFwiZXhwaXJlX3RpbWVcIjpcIlwiLFwic291cmNlX2lkXCI6XCJcIixcInR5cGVcIjpcIlwiLFwiY29ycF9pZFwiOlwiZm1fc3lzdGVtX2NvcnBcIn0iLCJleHAiOjQwOTI1OTkzNDksImp0aSI6ImFfNjhmZjBhZGY5OTcxNDQ0NThjNzViZWFiN2FjNTkzYWYifQ.W122WkT6QR4HZWbpalkpmirV9JWkDYcCkmNZoxCB_z8';
          this.map=new this.smartmapx.Map({
              container: 'main-map',
              mapId: 'map_id_1',
              center: [117.18423,39.040199],
              zoom: 7.9
            });
            this.map.addControl(new this.smartmapx.NavigationControl(),'top-right');
            this.map.addControl(new this.smartmapx.ScaleControl({
              maxWidth: 100,
              unit: 'm'
            }));
            this.imag=imag;
            this.map.on('load',() =>{
               var width = 64; // The image will be 64 pixels square
                var bytesPerPixel = 4; // Each pixel is represented by 4 bytes: red, green, blue, and alpha.
                var data = new Uint8Array(width * width * bytesPerPixel);
                
                for (var x = 0; x < width; x++) {
                for (var y = 0; y < width; y++) {
                var offset = (y * width + x) * bytesPerPixel;
                data[offset + 0] = y / width * 255; // red
                data[offset + 1] = x / width * 255; // green
                data[offset + 2] = 128;             // blue
                data[offset + 3] = 255;             // alpha
                }
                }
                
                this.map.addImage('gradient', {width: width, height: width, data: data});
                
                this.map.addLayer({
                "id": "points",
                "type": "symbol",
                "source": {
                "type": "geojson",
                "data": {
                "type": "FeatureCollection",
                "features": [{
                "type": "Feature",
                "geometry": {
                "type": "Point",
                "coordinates": [117.18423,39.040199]
                }
                }]
                }
                },
                "layout": {
                "icon-image": "gradient"
                }
                });
            });
        }
    }
}
</script>
<style lang="scss" scoped>
#main-map{
    width: 100%;
    height: 100%;
}
</style>